package org.gmr;


import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 日新精密导入产品数据
 */

public class RXJMTest1 {


    static String url = "http://171.8.68.158:19004/ccp-ecmp-service/web-api/dictProductConsumption/save";

    static String token = "bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJudW1iZXIiOiI2ODAwYzU2ZTQ2ZTBmYjAwMDc3NTMyMGYiLCJlbmhhbmNlT3JnYW5pemF0aW9uSW5mbyI6eyJyb290T3JnYW5pemF0aW9uSWQiOiJyb290X29yZ2FuaXphdGlvbl9yb290X3RlbmFudF9pZCIsInJvb3RPcmdhbml6YXRpb25OYW1lIjoi5Zu95py65LqS6IGUSURBQVMiLCJwYXJlbnRPcmdhbml6YXRpb25JZCI6IjY4MDA3MmUwNDZlMGZiMDAwNzc1MzEyZiIsImV4dGVybmFsUGFyZW50T3JnYW5pemF0aW9uSWQiOiI2ODAwNzJlMDQ2ZTBmYjAwMDc3NTMxMzAiLCJwYXJlbnRPcmdhbml6YXRpb25OYW1lIjoi6YOR5bee5pel5paw57K-5a-G5py65qKw5pyJ6ZmQ5YWs5Y-4IiwicGFyZW50T3JnYW5pemF0aW9uRnVsbFBhdGgiOiJyb290X29yZ2FuaXphdGlvbl9yb290X3RlbmFudF9pZC82MzdjNzllODQ2ZTBmYjAwMDdlZjcyMzAvNjgwMDcyZTA0NmUwZmIwMDA3NzUzMTJmIiwiZGVwYXJ0bWVudElkIjpudWxsLCJleHRlcm5hbERlcGFydG1lbnRJZCI6bnVsbCwiZGVwYXJ0bWVudE5hbWUiOm51bGwsInJvb3REZXBh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SU5BTF9FUVVJUCIsIkVOVEVSUFJJU0VfTU9EVUxFX0VORVJHWV9QQVkiLCJFTlRFUlBSSVNFX01PRFVMRV9NRVRFUl9HRVRXQVkiLCJNT0RVTEVfU1lTVEVNX0ZPUk1DQUxDX01BTkFHRU1FTlQiLCJFTlRFUlBSSVNFX01PRFVMRV9JVEVNRU5FUkdZX1RZUEUiLCJFTlRFUlBSSVNFX01PRFVMRV9JVEVNSVpFRF9NRVRFUiIsIk9QRVJBVElPTl9NT0RVTEVfTUVURVJfVFlQRSJdLCJqdGkiOiJlZjlkZDRkNi1hZDdhLTQ1YjUtYjY1MS1lYmQ2NTJiZThjZTkiLCJjbGllbnRfaWQiOiIxMTY4Y2I0YS0wMmU5LTQxMTktODdlYi05N2FjZDcxOWRlYTkifQ.NJox91OAkiikXOWUnS7zG6zIkOKkadY_YOvFyp3GQnOp1eCR-RWxFONBuYLHkF1Ep_lUI5y7Yd83-VOXrfa02VxHGAmUijfOY3Wygfk9RFmcjaTjH8Uk5BtLu7A-0htCA4kGtXobsJ8gDGKfdD7wm6eK5cVhLJz0xAxyK7cJzwZWVHNGlbOebzLxvHUw_Qy7I-p4ksZ5C-rdrMJheCPUQvuAsuL_aK0hIRevM4sd3gFX_rRka0BVhyhmBOOjPlU4c8b_qMG0HLjtt0o2l-raOra7-YyPJoJXvr11Vr6oMa9jJtetdV9Ch-KpB_j6Us_JeSN5oEym96jhGOrTA_FgDA";

    public static void main(String[] args) throws InterruptedException {

        ExcelReader reader = ExcelUtil.getReader("E:\\CodeSpace\\IDEA\\test\\test-1\\aa.xls", 0);

        Sheet sheet = reader.getSheet();

        for (int i = 91; i < 412; i++) {
            Row row = sheet.getRow(i);
            Cell name = row.getCell(1);

            Map<String, Object> map = new HashMap<>();
            map.put("name", name.toString());
            map.put("productType", "PRODUCT");
            HttpResponse response = null;
            response = HttpUtil.createPost(url)
                    .header("Authorization", token)
                    .body(JSONUtil.toJsonStr(map))
                    .execute();

            String parentUuid = null;
            if (response != null && response.isOk()) {
                String body = response.body();

                JSONObject object = new JSONObject(body);

                List<String> list = JSONUtil.toList(object.get("data").toString(), String.class);

                parentUuid = new JSONObject(list.get(0)).get("uuid").toString();
            }

            if (parentUuid == null || parentUuid.isEmpty()) {
                continue;
            }

            Cell nc1 = row.getCell(2);
            Cell nc2 = row.getCell(3);
            Cell nc3 = row.getCell(4);
            Cell nc4 = row.getCell(5);
            Cell mc1 = row.getCell(6);
            Cell mc2 = row.getCell(7);
            Cell mc3 = row.getCell(8);

            StringBuilder sb = new StringBuilder();
            if (nc1 != null && StrUtil.isNotBlank(nc1.toString())) {
                sb.append("NC1,");
            }
            if (nc2 != null && StrUtil.isNotBlank(nc2.toString())) {
                sb.append("NC2,");
            }
            if (nc3 != null && StrUtil.isNotBlank(nc3.toString())) {
                sb.append("NC3,");
            }
            if (nc4 != null && StrUtil.isNotBlank(nc4.toString())) {
                sb.append("NC4,");
            }

            if (mc1 != null && StrUtil.isNotBlank(mc1.toString())) {
                sb.append("MC1,");
            }
            if (mc2 != null && StrUtil.isNotBlank(mc2.toString())) {
                sb.append("MC2,");
            }
            if (mc3 != null && StrUtil.isNotBlank(mc3.toString())) {
                sb.append("MC3,");
            }

            String s = sb.toString();
            if (!s.isEmpty()) {
                String[] split = s.split(",");

                for (String process : split) {

                    Map<String, Object> data = new HashMap<>();
                    data.put("name", process);
                    data.put("parentUuid", parentUuid);
                    data.put("productType", "PROCESS");
                    HttpResponse response1 = HttpUtil.createPost(url)
                            .header("Authorization", token)
                            .body(JSONUtil.toJsonStr(data))
                            .execute();
                }
            }


            Thread.sleep(1000);

        }


    }


}
